package com.foreveross.vo;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Table(name = "order_service", catalog = "hrtenement")
public class OrderService implements java.io.Serializable {

	private String id;
	private HrCode orderType;
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date orderTime;
	// private Tenement tenementId;
	private String phone;
	private String orderNo;
	private String status;
	private String userName;
	private String orderTypeName;
	private String orderTypeId;
	private String address;
	private HouseUser userId;
	private String hrHousesName;
	private HrHouses houseId;

	public OrderService() {
	}

	@Id
	@GenericGenerator(name = "idGenerator", strategy = "uuid")
	@GeneratedValue(generator = "idGenerator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "order_time")
	public Date getOrderTime() {
		return orderTime;
	}

	public void setOrderTime(Date orderTime) {
		this.orderTime = orderTime;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "order_type")
	@NotFound(action = NotFoundAction.IGNORE)
	public HrCode getOrderType() {
		return orderType;
	}

	public void setOrderType(HrCode orderType) {
		this.orderType = orderType;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Transient
	public String getOrderTypeName() {
		if (orderType != null)
			return orderType.getCodeDesc();
		return orderTypeName;
	}

	public void setOrderTypeName(String orderTypeName) {
		this.orderTypeName = orderTypeName;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "order_no")
	public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	@Transient
	public String getHrHousesName() {
		if (userId != null)
			return userId.getHousesName();
		return hrHousesName;
	}
	
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id")
	@NotFound(action = NotFoundAction.IGNORE)
	public HouseUser getUserId() {
		return userId;
	}

	public void setUserId(HouseUser userId) {
		this.userId = userId;
	}

	public void setHrHousesName(String hrHousesName) {
		this.hrHousesName = hrHousesName;
	}
	
    @Transient
	public String getOrderTypeId() {
		if (orderType != null)
			return orderType.getCodeId();
		return orderTypeId;
	}

	public void setOrderTypeId(String orderTypeId) {
		this.orderTypeId = orderTypeId;
	}

	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "house_id")
	@NotFound(action = NotFoundAction.IGNORE)
	public HrHouses getHouseId() {
		return houseId;
	}

	public void setHouseId(HrHouses houseId) {
		this.houseId = houseId;
	}
	
	

}
